//
//  ZCStatusModel.swift
//  weibo
//
//  Created by Ning Xie on 16/8/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class ZCStatusModel: NSObject {

    //  发微博时间
    var created_at: String?
    //  微博id
    var id: Int64 = 0
    //  微博内容
    var text: String?
    //  来源
    var source: String?
    //  关注用户的模型
    var user: ZCUserModel?
    
    //  转发数
    var reposts_count: Int = 0
    //  评论数
    var comments_count:	Int = 0
    //	表态数
    var attitudes_count: Int = 0
    //转发微博视图
    var retweeted_status:ZCStatusModel?
    
    //图片信息
    var pic_urls:[ZCStatusPicModel]?
    
    //视频信息
    var video_urls:String?{
        
        guard let str = self.text where str.containsString("http://t.cn/") else{
            return nil
        }
        
        //执行到此,说明是有视频的
        let index = str.rangeOfString("http://t.cn/")
        
        return str.substringWithRange((index?.startIndex)!..<(index?.endIndex.advancedBy(7))!)
        
        
    }
    
    
    init(dic:[String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dic)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            guard let dic = value as? [String:AnyObject] else{
                return
            }
        
            user = ZCUserModel(dic: dic)
        }else if key == "retweeted_status"{
            
            guard let dic = value as? [String:AnyObject] else{
                return
            }
           
            retweeted_status = ZCStatusModel(dic: dic)
        }else if key == "pic_urls"{
            
            guard let dicArr = value as? [[String:AnyObject]] else{
                return
            }
            var tempArr = [ZCStatusPicModel]()
            for dic in dicArr {
                
                let picInfo = ZCStatusPicModel(dic: dic)
                tempArr.append(picInfo)
            }
            self.pic_urls = tempArr
        }
        else{
            super.setValue(value, forKey: key)
        }
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    

}
